<template>
  <div class="tab1">
    <div class="searchDiv">
      <Form :model="searchItem" :label-width="90">
        <Row :gutter="10">
          <Col span="24" style="margin-bottom:15px;">
            <!-- <Button type="info" class="marRight" @click="upload">导入EXcel</Button> -->
            <Upload
              style="float:left;"
              :headers="fileheader"
              :on-success="fileSuccess"
              :show-upload-list="false"
              :action="apihost + '/admin-api/admins/equipmentVibration/upload'"
            >
              <Button type="info" class="marRight">导入EXcel</Button>
            </Upload>
            <Button type="primary" class="marRight" @click="add"
              >录入数据</Button
            >
            <Button type="success" @click="download">导出Excel</Button>
          </Col>
          <Col span="6">
            <FormItem label="电站">
              <Select
                v-model="searchItem.powerStation"
                clearable
                filterable
                @on-change="getHd"
              >
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="searchItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option
                  v-for="(item, index) in HBnumberList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="searchItem.aircrewNumber"
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option
                  v-for="(item, index) in JZnumberList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <Button type="primary" @click="addJz">加入对比</Button>
          </Col>
        </Row>
        <div v-if="tagList1.length > 0" style="margin-bottom:10px;">
          <Tag
            type="border"
            color="primary"
            v-for="item in tagList1"
            :key="item"
            :name="item"
            closable
            @on-close="handleClose1"
            >{{ item }}</Tag
          >
        </div>
        <Row :gutter="10">
          <Col span="6">
            <FormItem label="分析参数">
              <Select v-model="searchItem.weizhi">
                <Option v-for="(item, index) in mainCode" :value="item.value">{{
                  item.name
                }}</Option>
              </Select>
            </FormItem>
          </Col>
          <!-- <Col span="6">
            <FormItem label="时间">
              <DatePicker
                type="datetimerange"
                format="yyyy-MM-dd HH:mm:ss"
                @on-change="handleChangeSearchClock"
                placeholder="选择日期和时间"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col> -->
          <Col span="6">
            <Button type="primary" @click="addCs">加入对比</Button>
          </Col>
        </Row>
        <div v-if="tagList2.length > 0" style="margin-bottom:10px;">
          <Tag
            type="border"
            color="success"
            v-for="item in tagList2"
            :key="item"
            :name="item"
            closable
            @on-close="handleClose2"
            >{{ item }}</Tag
          >
        </div>
      </Form>
    </div>
    <div
      id="myChart"
      style="width:100%;height:500px;border-top:1px solid #ccc;padding-top:10px;"
    ></div>
    <Table
      :loading="loading"
      border
      :columns="columns"
      :data="tableData"
    ></Table>

    <Page
      show-total
      :total="total"
      :current="pageNo"
      :page-size="pageSize"
      style="margin:20px auto;text-align:center"
      @on-change="changePage"
    />
    <!-- 新增 -->
    <Modal
      :mask-closable="false"
      v-model="modal1"
      title="录入数据"
      width="1000"
      :styles="{ top: '20px' }"
      @on-ok="ok"
      :loading="btnClick"
    >
      <Form :label-width="160">
        <Row :gutter="10" class="xzjz">
          <Col span="8">
            <FormItem label="电站">
              <Select
                v-model="formItem.powerStation"
                clearable
                filterable
                @on-change="getHd"
              >
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem label="HD编号">
              <Select
                v-model="formItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option
                  v-for="(item, index) in HBnumberList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem label="机组编号">
              <Select
                v-model="formItem.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option
                  v-for="(item, index) in JZnumberList"
                  :value="item"
                  :key="index"
                  >{{ item }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem label="试验时间">
              <DatePicker
                type="datetime"
                v-model="formItem.experimentTime"
                @on-change="time"
                format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem label="功率KW">
              <Input v-model="formItem.power" placeholder="请输入"></Input>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <table width="“100%”" class="addTable">
        <tr>
          <th width="40%">位置/方向</th>
          <th width="20%">水平</th>
          <th width="20%">垂直</th>
          <th width="20%">轴向</th>
        </tr>
        <tr>
          <td>柴油机001M0驱动器</td>
          <td>
            <Input v-model="formItem.driveX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.driveY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.driveZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>柴油机001M0中部</td>
          <td>
            <Input v-model="formItem.middleX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.middleY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.middleZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>柴油机002M0驱动器</td>
          <td>
            <Input v-model="formItem.mo1DriveX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1DriveY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1DriveZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>柴油机002M0中部</td>
          <td>
            <Input v-model="formItem.mo1MiddleX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1MiddleY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1MiddleZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>柴油机002M0非驱动端</td>
          <td>
            <Input v-model="formItem.mo1NotDriveX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1NotDriveY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.mo1NotDriveZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>基座一002M0</td>
          <td>
            <Input
              v-model="formItem.mo1SubstrateX"
              placeholder="请输入"
            ></Input>
          </td>
          <td>
            <Input
              v-model="formItem.mo1SubstrateY"
              placeholder="请输入"
            ></Input>
          </td>
          <td>
            <Input
              v-model="formItem.mo1SubstrateZ"
              placeholder="请输入"
            ></Input>
          </td>
        </tr>
        <tr>
          <td>发电机001M0侧</td>
          <td><Input v-model="formItem.mo1X" placeholder="请输入"></Input></td>
          <td><Input v-model="formItem.mo1Y" placeholder="请输入"></Input></td>
          <td><Input v-model="formItem.mo1Z" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>发电机002M0侧</td>
          <td><Input v-model="formItem.mo2X" placeholder="请输入"></Input></td>
          <td><Input v-model="formItem.mo2Y" placeholder="请输入"></Input></td>
          <td><Input v-model="formItem.mo2Z" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>柴油机001M0非驱动端</td>
          <td>
            <Input v-model="formItem.notDriveX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.notDriveY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.notDriveZ" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>基座一001M0</td>
          <td>
            <Input v-model="formItem.substrate1X" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.substrate1Y" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.substrate1Z" placeholder="请输入"></Input>
          </td>
        </tr>
        <tr>
          <td>基座发电机</td>
          <td>
            <Input v-model="formItem.substrateX" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.substrateY" placeholder="请输入"></Input>
          </td>
          <td>
            <Input v-model="formItem.substrateZ" placeholder="请输入"></Input>
          </td>
        </tr>
      </table>
    </Modal>

    <Modal
      :mask-closable="false"
      v-model="modal3"
      width="360"
      class-name="vertical-center-modal"
      @on-ok="remove(delID)"
    >
      <p slot="header" style="color:#f60;text-align:center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认删除</span>
      </p>
      <div style="text-align:center">
        <p>确认删除此数据么？</p>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  getTableData1,
  add1,
  edit1,
  delete1,
  download1
} from "@/api/offlineTrend";
import { getSelectOption, getAllEqu } from "@/api/select";
import { getToken } from "@/libs/util";
export default {
  data() {
    return {
      btnClick: false,
      loading: true,
      fileheader: {
        Authorization: "Bearer " + (getToken() ? getToken() : "")
      },
      delID: 0,
      modal3: false,
      modal1: false,
      pageNo: 1,
      pageSize: 10,
      total: 0,
      isAdd: true,
      searchItem: {
        powerStation: "",
        hdNumber: "",
        aircrewNumber: "",
        weizhi: "driveX"
      },
      allEquList: [],
      allEquList2: [],
      powerStationList: [],
      HBnumberList: [],
      JZnumberList: [],
      JZnumberList2: [],
      formItem: {},
      columns: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center"
        },
        {
          title: "核岛编号",
          key: "hdNumber"
        },
        {
          title: "机组编号",
          key: "aircrewNumber"
        },
        {
          title: "试验时间",
          key: "experimentTime"
        },
        {
          title: "功率KW",
          key: "power"
        },
        {
          title: "记录人",
          key: "weizhi"
        },
        {
          title: "记录时间",
          key: "spgg"
        },
        {
          title: "操作",
          key: "action",
          width: 200,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(JSON.stringify(params));
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.openDel(params.row.id);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      tableData: [],
      timeList: [],
      colorarry: [
        "#c12e34",
        "#e6b600",
        "#0098d9",
        "#2b821d",
        "#005eaa",
        "#339ca8",
        "#a134d4",
        "#32a487",
        "#eb1e99",
        "#ff8819"
      ],
      option: {
        tooltip: {},
        legend: {
          data: [],
          top: "10",
          type: "scroll"
        },
        dataZoom: [
          {
            type: "slider", //数据滑块
            start: 0
          },
          {
            type: "inside" //使鼠标在图表中时滚轮可用
          }
        ],
        xAxis: {
          type: "time",
          axisLabel: {
            interval: 0,
            formatter: function(time) {
              const dateTime = new Date(time);
              const year = dateTime.getFullYear();
              const month =
                dateTime.getMonth() + 1 < 10
                  ? "0" + (dateTime.getMonth() + 1)
                  : dateTime.getMonth() + 1;
              const date =
                dateTime.getDate() < 10
                  ? "0" + dateTime.getDate()
                  : dateTime.getDate();
              const hour =
                dateTime.getHours() < 10
                  ? "0" + dateTime.getHours()
                  : dateTime.getHours();
              const minute =
                dateTime.getMinutes() < 10
                  ? "0" + dateTime.getMinutes()
                  : dateTime.getMinutes();
              const second =
                dateTime.getSeconds() < 10
                  ? "0" + dateTime.getSeconds()
                  : dateTime.getSeconds();
              return (
                year +
                "-" +
                month +
                "-" +
                date +
                " " +
                hour +
                ":" +
                minute +
                ":" +
                second
              );
            }
          }
        },
        yAxis: {
          type: "value"
        },
        series: []
      },
      tagList1: [],
      jzCheckList: [],
      tagList2: ["柴油机001M0驱动器水平"],
      csList: ["driveX"],
      mainCode: [
        { value: "driveX", name: "柴油机001M0驱动器水平" },
        { value: "driveY", name: "柴油机001M0驱动器垂直" },
        { value: "driveZ", name: "柴油机001M0驱动器轴向" },
        { value: "middleX", name: "柴油机001M0中部水平" },
        { value: "middleY", name: "柴油机001M0中部垂直" },
        { value: "middleZ", name: "柴油机001M0中部轴向" },
        { value: "mo1DriveX", name: "柴油机002M0驱动器水平" },
        { value: "mo1DriveY", name: "柴油机002M0驱动器垂直" },
        { value: "mo1DriveZ", name: "柴油机002M0驱动器轴向" },
        { value: "mo1MiddleX", name: "柴油机002M0中部水平" },
        { value: "mo1MiddleY", name: "柴油机002M0中部垂直" },
        { value: "mo1MiddleZ", name: "柴油机002M0中部轴向" },
        { value: "mo1NotDriveX", name: "柴油机002M0非驱动端水平" },
        { value: "mo1NotDriveY", name: "柴油机002M0非驱动端垂直" },
        { value: "mo1NotDriveZ", name: "柴油机002M0非驱动端轴向" },
        { value: "mo1SubstrateX", name: "基座一002M0水平" },
        { value: "mo1SubstrateY", name: "基座一002M0垂直" },
        { value: "mo1SubstrateZ", name: "基座一002M0轴向" },
        { value: "mo1X", name: "发电机001M0侧水平" },
        { value: "mo1Y", name: "发电机001M0侧垂直" },
        { value: "mo1Z", name: "发电机001M0侧轴向" },
        { value: "mo2X", name: "发电机002M0侧水平" },
        { value: "mo2Y", name: "发电机002M0侧垂直" },
        { value: "mo2Z", name: "发电机002M0侧轴向" },
        { value: "notDriveX", name: "柴油机001M0非驱动端水平" },
        { value: "notDriveY", name: "柴油机001M0非驱动端垂直" },
        { value: "notDriveZ", name: "柴油机001M0非驱动端轴向" },
        { value: "substrate1X", name: "基座一001M0水平" },
        { value: "substrate1Y", name: "基座一001M0垂直" },
        { value: "substrate1Z", name: "基座一001M0轴向" },
        { value: "substrateX", name: "基座发电机水平" },
        { value: "substrateY", name: "基座发电机垂直" },
        { value: "substrateZ", name: "基座发电机轴向" }
      ]
    };
  },
  methods: {
    download() {
      download1({ pageNo: 1, pageSize: 100 }).then(res => {
         const blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;'});

        const ie = navigator.userAgent.match(/MSIE\s([\d.]+)/),
            ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/),
            ieEDGE = navigator.userAgent.match(/Edge/g),
            ieVer = (ie ? ie[1] : (ie11 ? 11 : (ieEDGE ? 12 : -1)));
        console.log('ie:' + ie);
        console.log('ieVer:' + ieVer);
        if (ie && ieVer < 10) {
            this.message.error('No blobs on IE<10');
            return;
        }
        if (ieVer > -1) {
            window.navigator.msSaveBlob(blob, '柴油机振动监测数据.xlsx');
        } else {
            const url = window.URL.createObjectURL(blob);
            let link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('download', '柴油机振动监测数据.xlsx');
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
        // const blob = new Blob([res]); //处理文档流
        // const fileName = "柴油机振动监测数据.xlsx";
        // const elink = document.createElement("a");
        // elink.download = fileName;
        // elink.style.display = "none";
        // elink.href = URL.createObjectURL(blob);
        // document.body.appendChild(elink);
        // elink.click();
        // URL.revokeObjectURL(elink.href); // 释放URL 对象
        // document.body.removeChild(elink);
      });
    },
    fileSuccess(response, file, fileList) {
      this.$Message.info("导入成功");
      this.getDataList();
    },
    time(e) {
      this.formItem.experimentTime = e;
    },
    handleClose1(event, name) {
      const index = this.tagList1.indexOf(name);
      this.tagList1.splice(index, 1);
      this.search();
    },
    handleClose2(event, name) {
      const index = this.tagList2.indexOf(name);
      this.tagList2.splice(index, 1);
      this.csList.splice(index, 1);
      this.search();
    },
    addJz() {
      if (this.tagList1.length * this.tagList2.length > 9) {
        this.$Message.info("选择的对比已经很多了");
        return false;
      }
      if (this.tagList1.indexOf(this.searchItem.aircrewNumber) == -1) {
        let aaa = this.tableData.filter(
          item => item.aircrewNumber == this.searchItem.aircrewNumber
        );
        if (aaa.length == 0) {
          this.$Message.info("此筛选条件下无数据");
          return false;
        }
        this.tagList1.push(this.searchItem.aircrewNumber);
        this.jzCheckList = this.jzCheckList.concat(aaa);
        this.search();
      }
    },
    addCs() {
      if (this.tagList1.length * this.tagList2.length > 9) {
        this.$Message.info("选择的对比已经很多了");
        return false;
      }
      let bbb = this.mainCode.filter(
        item => item.value == this.searchItem.weizhi
      );
      if (this.tagList2.indexOf(bbb[0].name) == -1) {
        this.csList.push(this.searchItem.weizhi);
        this.tagList2.push(bbb[0].name);
        this.search();
      }
    },
    search() {
      this.option.legend.data = [];
      this.option.series = [];
      this.$echarts.init(document.getElementById("myChart")).dispose();
      let that = this;
      for (let i = 0; i < that.tagList1.length; i++) {
        for (let j = 0; j < that.tagList2.length; j++) {
          that.option.legend.data.push(
            that.tagList1[i] + "-" + that.tagList2[j]
          );
          let arry = [];
          let aaa = this.jzCheckList.filter(
            item => item.aircrewNumber == that.tagList1[i]
          );
          for (let n = 0; n < aaa.length; n++) {
            arry.push([aaa[n].experimentTime, aaa[n][that.csList[j]]]);
          }
          let sjcolor = that.color16();
          that.option.series.push({
            name: that.tagList1[i] + "-" + that.tagList2[j],
            data: arry,
            type: "line",
            smooth: true,
            symbolSize: 8, //折线点的大小
            itemStyle: {
              normal: {
                color: sjcolor, //折线点的颜色
                lineStyle: {
                  color: sjcolor //折线的颜色
                }
              }
            }
          });
        }
      }
      that.$echarts
        .init(document.getElementById("myChart"))
        .setOption(that.option);
    },
    color16() {
      var n = Math.floor(Math.random() * this.colorarry.length + 1) - 1;
      return this.colorarry[n];
    },
    getDataList() {
      let that = this;
      that.tableData = [];
      getTableData1({ pageNo: this.pageNo, pageSize: this.pageSize })
        .then(res => {
          if (res.code == 0) {
            that.loading = false;
            that.total = res.data.total;
            that.tableData = res.data.list.sort(function(a, b) {
              return a.experimentTime < b.experimentTime ? 1 : -1;
            });

            that.allEquList2 = that.allEquList.filter(
              item => item.powerStation == res.data.list[0].powerStation
            );
            let arr2 = that.allEquList2.map(function(item) {
              return item.hdNumber;
            });
            that.HBnumberList = [...new Set(arr2)];

            let arr3 = that.allEquList2.filter(
              item => item.hdNumber == res.data.list[0].hdNumber
            );
            let arr4 = arr3.map(function(item) {
              return item.aircrewNumber;
            });
            that.JZnumberList = [...new Set(arr4)];

            that.searchItem.powerStation = res.data.list[0].powerStation;
            that.searchItem.hdNumber = res.data.list[0].hdNumber;
            that.searchItem.aircrewNumber = res.data.list[0].aircrewNumber;
            that.tagList1[0] = res.data.list[0].aircrewNumber;
            that.jzCheckList = res.data.list.filter(
              item => item.aircrewNumber == res.data.list[0].aircrewNumber
            );
            that.search();

          }
        })
        .catch(err => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    getAllEqument() {
      getAllEqu(null).then(res => {
        this.allEquList = res.data;
        let arr = res.data.map(function(item) {
          return item.powerStation;
        });
        this.powerStationList = [...new Set(arr)];
        this.getDataList();
      });
    },
    getHd(e) {
      this.JZnumberList = [];
      this.allEquList2 = this.allEquList.filter(item => item.powerStation == e);
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];
    },
    getJz(e) {
      let arr = this.allEquList2.filter(item => item.hdNumber == e);
      let arr2 = arr.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr2)];
    },
    openDel(id) {
      this.modal3 = true;
      this.delID = id;
    },
    add() {
      this.formItem = {};
      this.isAdd = true;
      this.modal1 = true;
    },
    edit(params) {
      this.formItem = JSON.parse(params).row;

      this.isAdd = false;
      this.modal1 = true;
      this.allEquList2 = this.allEquList.filter(
        item => item.powerStation == this.formItem.powerStation
      );
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];

      let arr3 = this.allEquList2.filter(
        item => item.hdNumber == this.formItem.hdNumber
      );
      let arr4 = arr3.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr4)];
    },
    timeFormat(time) {
      if(time instanceof Date==false){
        return time
      }
      const dateTime = new Date(time);
      const year = dateTime.getFullYear();
      const month = this.addZero(dateTime.getMonth() + 1);
      const date = this.addZero(dateTime.getDate());
      const hour = this.addZero(dateTime.getHours());
      const minute = this.addZero(dateTime.getMinutes());
      const second = this.addZero(dateTime.getSeconds());
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    addZero(v) {
      return v < 10 ? "0" + v : v;
    },
    remove(id) {
      delete1({ id: id })
        .then(res => {
          if (res.code == 0) {
            this.$Message.info("删除成功");
            this.pageNo = 1;
            this.getDataList();
          } else {
            this.$Message.info(res.message);
          }
        })
        .catch(err => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    ok() {
      this.btnClick = true;
      if (this.isAdd) {
        add1(this.formItem)
          .then(res => {
            if (res.code == 0) {
              this.$Message.info("新增成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch(err => {
            console.error("err>" + JSON.stringify(err));
          });
      } else {
        this.formItem.experimentTime = this.timeFormat(
          this.formItem.experimentTime
        );
        edit1(this.formItem)
          .then(res => {
            if (res.code == 0) {
              this.$Message.info("编辑成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch(err => {
            console.error("err>" + JSON.stringify(err));
          });
      }
    },
    /** 分页 */
    changePage(pageNo) {
      this.pageNo = pageNo;
      this.getDataList();
    }
  },
  mounted() {
    this.getAllEqument();

    // 基于准备好的dom，初始化echarts实例
    let myChart = this.$echarts.init(document.getElementById("myChart"));
    // 绘制图表
    myChart.setOption(this.option);
  }
};
</script>

<style lang="less">
.tab1 {
  background: #fff;
  height: 100%;
  font-size: 14px;
  .searchDiv {
    .marRight {
      margin-right: 15px;
    }
  }
  .ivu-form-item {
    margin-bottom: 15px;
  }
}
.addTable {
  border-collapse: collapse;
  width: 100%;
  th {
    background: #f5f5f5;
  }
  td,
  th {
    border: 1px solid #eaeaea;
    padding: 10px 20px;
    text-align: center;
    .ivu-input {
      text-align: center;
    }
  }
}
</style>
